﻿using System;
using Assist;
using Autodesk.Revit.DB;

namespace YRevitJig
{
	public class ViewAssist
	{
		public static bool ViewValidating(Autodesk.Revit.DB.Document doc, View activeView)
		{
			bool result;
			if (activeView.GetType() == typeof(ViewPlan))
			{
				ViewPlan viewPlan = activeView as ViewPlan;
				if (viewPlan.SketchPlane == null)
				{
					Plane plane = RevitVersionFuncs.CreatePlanByOriginAndBasis(viewPlan.Origin, viewPlan.RightDirection, viewPlan.UpDirection);
					Transaction transaction = new Transaction(doc);
					transaction.Start("new sketchPlane");
					activeView.SketchPlane = SketchPlane.Create(doc, plane);
					transaction.Commit();
				}
				result = true;
			}
			else if (activeView.GetType() == typeof(ViewSection))
			{
				ViewSection viewSection = activeView as ViewSection;
				if (viewSection.SketchPlane == null)
				{
					Plane plane = RevitVersionFuncs.CreatePlanByOriginAndBasis(viewSection.Origin, viewSection.RightDirection, viewSection.UpDirection);
					Transaction transaction = new Transaction(doc);
					transaction.Start("new sketchPlane");
					activeView.SketchPlane = SketchPlane.Create(doc, plane);
					transaction.Commit();
				}
				result = true;
			}
			else
			{
				result = false;
			}
			return result;
		}
	}
}
